package com.viroyal.monitorlib.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import com.hwangjr.rxbus.RxBus;
import com.suntiago.baseui.utils.log.Slog;

/**
 * 开机自启动的广播
 * Created by yj on 2017/5/31.
 */

public class MessageForwardingReceiver extends BroadcastReceiver {

    private final String TAG = getClass().getSimpleName();
    static final String ACTION_RECEIVE = "com.viroyal.permission.viroyal.receive.netty";
    static final String ACTION_SEND = "com.viroyal.permission.viroyal.send.netty";

    @Override
    public void onReceive(Context context, Intent intent) {
        Slog.d(TAG, "onReceive  [context, intent]:" + intent.getAction());
        if (intent.getAction().equals(ACTION_RECEIVE)) {
            //收到消息
            String msg = intent.getStringExtra("content");

            if (!TextUtils.isEmpty(msg)) {
                Slog.d(TAG, "onReceive  [context, intent]:" + msg);
                RxBus.get().post("onRecvSocketIotMessage", msg);
            }
        } else if (intent.getAction().equals(ACTION_SEND)) {
            //发出消息
            String msg = intent.getStringExtra("content");
            if (!TextUtils.isEmpty(msg)) {
                Slog.d(TAG, "onReceive  [context, intent]:" + msg);
                RxBus.get().post("send_msg", msg);
            }
        }
    }
}
